home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Eagles Nest BBS 5
/
Eagles_Nest_Mac_Collection_Disc_5.TOAST
/
Other Non-Macintosh Text
/
CDVvalidate
< prev
next >
Wrap
Text File
|
1993-09-03
|
3KB
|
123 lines
The first part of this doument is a quick summary of card number input
validation criteria. The second part of this document is a general description
of the MOD 10 cdv algorithm. The third part is a VAX BASIC implementation of a
MOD 10 cdv validation routine. The algorith and the program came from different
sources, and so do not necessarily reflect one another. The BASIC program does
indeed work, and will ID bad credit card input.
Card Number Validation
**********************
VISA starts with "4" len = 13 or 16
MasterCard starts with "5" len = 13 or 16
Discover starts with "6011" len = 16
Amex starts with "37" len = 15
? Diners, Carte Blanche starts with "38", len = 15 (not sure on this one)
all card numbers are mod 10 CDV'd
MOD 10 CDV algorithm
********************
A) Starting from thr RIGHTMOST digit and working to the left, multiply one
digit by 2, the next by 1, the next by and so forth.
B) Sum the digits of any two digit numbers produced.
C) Add all of the resultant figures.
D) Subtract that number from the next highest multiple of 10 and use that
as a check digit.
examples:
# 12345 11111 66666 126749
A) 2,2,6,4,10 2,1,2,1,2 12,6,12,6,12 1,4,6,14,4,18
B) 2,2,6,4,1 2,1,2,1,2 3,6,3,6,3 1,4,6,5,4,9
C) 15 8 21 29
D) 5 2 9 1
123455 111112 666669 1267491
MOD 10 cdv validation program
*****************************
function byte mod_10_cdv(string s$_in)
! description : Performs a MOD 10 CDV validation of a
! numeric string. Accomodates numbers of
! up to 20 digits in length. returns -1 if cdv is correct
! 0 if not
!
option type = explicit
declare string constant c$_s_zero_fill_1 = "<0>"
record cdv_string
variant
case
string s$_digits = 20%
case
string s$_digit(1% to 20%) = 1%
end variant
end record
declare cdv_string cdv
declare byte b$_idx &
, b$_digit
declare double d$_total &
, d$_1 &
, d$_2
declare string s$_number
on error goto error_handler
mod_10_cdv = 0%
s$_number = edit$(s$_in, -1%)
exit function if len(s$_number) > 20%
rset cdv::s$_digits = "00000000000000000000" + s$_number
for b$_idx = 1% to 19% step 2%
b$_digit = 2 * integer(cdv::s$_digit(b$_idx), byte)
b$_digit = b$_digit - 9% if b$_digit > 9%
cdv::s$_digit(b$_idx) = format$(b$_digit, c$_s_zero_fill_1)
next b$_idx
d$_total = 0.0
for b$_idx = 1% to 19%
d$_total = d$_total + real(cdv::s$_digit(b$_idx), double)
next b$_idx
d$_1 = (d$_total - (int (d$_total / 10)) * 10) + real(cdv::s$_digit(20%), double)
d$_2 = int(d$_1 / 10)
if (d$_1 - (d$_2 * 10)) = 0 then
mod_10_cdv = -1%
end if
exit function
error_handler:
resume exit_function
exit_function:
end function